#ifndef VSCOLLAPSERECORD_H
#define VSCOLLAPSERECORD_H
#include "VSObject.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSCollapseRecord : public VSObject
	{
		//RTTI
		DECLARE_RTTI;
	protected:
		
		unsigned int m_uiDesireRecordID;
	public:
		unsigned int m_uiCurRecordID;
		VSCollapseRecord();
		virtual ~VSCollapseRecord() = 0;
		inline unsigned int DesireRecordID()const
		{
			return m_uiDesireRecordID;
		}
		inline void SetDesireRecordID(unsigned int DesireRecordID)
		{
			if (DesireRecordID <GetRecordNum())
			{
				m_uiDesireRecordID = DesireRecordID;
			}
		}
		virtual unsigned int GetRecordNum() = 0;
	public:

	};
	typedef VSPointer<VSCollapseRecord> VSCollapseRecordPtr;
	class VSCollapseRecordTri : public VSCollapseRecord
	{
		//PRIORITY
		
		//RTTI
		DECLARE_RTTI;
	public:
		VSCollapseRecordTri();
		~VSCollapseRecordTri();
		class RecordInfo
		{
		public:
			RecordInfo()
			{
				m_uiKeep = 0 ;
				m_uiThrow = 0;
				m_uiLeftTraingleNum = 0;
				m_MapIndex.Clear();
			}
			~RecordInfo()
			{
			
			}
			unsigned int m_uiKeep;
			unsigned int m_uiThrow;
			unsigned int m_uiLeftTraingleNum;
			VSArray<unsigned int>	m_MapIndex;

			unsigned int DiskUse()const
			{
				unsigned int uiUsed = 0;
				uiUsed += sizeof(unsigned int) * 3;
				uiUsed += sizeof(unsigned int);
				uiUsed += sizeof(unsigned int ) * m_MapIndex.GetNum();
				return uiUsed;
			}
			bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
			
			bool Load(VSStream & rStream,unsigned int &iSaveUse);
			
		};
		friend class VSCreateClodTriFactory;
		
		virtual unsigned int GetRecordNum()
		{
			return m_RecordInfo.GetNum();
		}
		friend class VSTriangleSet;
	public:
		static bool RegisterMainFactory();
	private:
		static bool InitialClassFactory();	
		static VSObject * FactoryFunc();
		static bool ms_bRegisterMainFactory;
	protected:
		VSArray<RecordInfo> m_RecordInfo;
	public:

		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);
	};
	typedef VSPointer<VSCollapseRecordTri> VSCollapseRecordTriPtr;


	class VSCollapseRecordLine : public VSCollapseRecord
	{
		//PRIORITY
		
		//RTTI
		DECLARE_RTTI;
	public:
		VSCollapseRecordLine();
		~VSCollapseRecordLine();
		class RecordInfo
		{
		public:
			RecordInfo()
			{
				m_uiKeep = VSMAX_INTEGER ;
				m_uiThrow = VSMAX_INTEGER;
				m_uiLeftEdgeNum = 0;
				m_MapIndex = VSMAX_INTEGER;
			}
			~RecordInfo()
			{

			}
			unsigned int m_uiKeep;
			unsigned int m_uiThrow;
			unsigned int m_uiLeftEdgeNum;
			unsigned int	m_MapIndex;

			unsigned int DiskUse()const
			{
				unsigned int uiUsed = 0;
				uiUsed += sizeof(unsigned int) * 4;
				return uiUsed;
			}
			bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		
			bool Load(VSStream & rStream,unsigned int &iSaveUse);
		
		};
		friend class VSCreateClodLineFactory;

		friend class VSLineSet;
		virtual unsigned int GetRecordNum()
		{
			return m_RecordInfo.GetNum();
		}
		friend class VSLineSet;
	public:
		static bool RegisterMainFactory();
	private:
		static bool InitialClassFactory();	
		static VSObject * FactoryFunc();
		static bool ms_bRegisterMainFactory;
	protected:
		VSArray<RecordInfo> m_RecordInfo;
	public:

		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);
	};
	typedef VSPointer<VSCollapseRecordLine> VSCollapseRecordLinePtr;
}
#endif